package cn.sunxyz.sample.plugin;

import cn.sunxyz.common.utils.reflect.ClassUtil;
import cn.sunxyz.common.utils.reflect.ReflectionUtil;
import cn.sunxyz.core.bean.plugin.AbstractPlugin;
import cn.sunxyz.sample.annotation.IAnn;

import java.lang.reflect.Method;
import java.util.Objects;

/**
 * Created by yangrd on 2017/5/26.
 */
public class IAnnPlugin extends AbstractPlugin {
    @Override
    public Object createTarget(Class<?> targetClazz, Object target) {
        if (targetClazz.isAnnotationPresent(IAnn.class)) {
            //提供动态的修改值
            Method setNameMethod = ClassUtil.getSetterMethod(targetClazz, "name", String.class);
            if (Objects.nonNull(setNameMethod)) {
                ReflectionUtil.invokeMethod(target, setNameMethod, "abc");
            }
        }
        return target;
    }
}
